package com.ruan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.entity.Knowledge;
import com.ruan.entity.Order;
import com.ruan.entity.R;
import com.ruan.query.KnowledgeQuery;
import com.ruan.service.KnowledgeService;
import com.ruan.mapper.KnowledgeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 59499
* @description 针对表【tb_knowledge】的数据库操作Service实现
* @createDate 2023-09-20 15:00:05
*/
@Service
public class KnowledgeServiceImpl extends ServiceImpl<KnowledgeMapper, Knowledge>
    implements KnowledgeService{

    @Autowired
    private KnowledgeMapper knowledgeMapper;

    @Override
    public R<IPage<Knowledge>> queryKnowledge(KnowledgeQuery knowledgeQuery) {
        QueryWrapper<Knowledge> wrapper = new QueryWrapper<>();
        wrapper.select("knowledge_id","title","content","pic_path","own_name","create_time","update_time");
        if (knowledgeQuery.getSearchValue() != null && !Objects.equals(knowledgeQuery.getSearchValue(), "")){
            wrapper.like("title",knowledgeQuery.getSearchValue());
        }
        Page<Knowledge> knowledgePage = new Page<>(knowledgeQuery.getPage(),knowledgeQuery.getSize());
        IPage<Knowledge> knowledgeIPage = knowledgeMapper.selectPage(knowledgePage,wrapper);
        return R.ok("查询成功",knowledgeIPage);
    }

    @Override
    public R<Knowledge> getKnowLedgeDetail(Integer knowledgeId) {
        QueryWrapper<Knowledge> wrapper = new QueryWrapper<>();
        wrapper.select("title","content","pic_path","own_name","create_time","update_time");
        wrapper.eq("knowledge_id",knowledgeId);
        Knowledge knowledge = knowledgeMapper.selectOne(wrapper);
        return R.ok("查询成功",knowledge);
    }
}




